Author: theany
01.02
17/02/2025
Here is another one. This is from the JS codebase.
ws.new_channel = {
_id: channel_id,
subserver_id: ws.subserver_id
};
ws.is_channel_delete = true;
So in first glance the above line might seem fine. But the context here is ws is a websocket object and this .new_channel binding to that websocket is happening in delete channel action. Yes a binding called new_channel is happening to new_channel. Since this is socket based system there'll be no race conditions etc but this is confusing. It looks like it serves no purpose. But if you delete it, the listener of this action won't be informed. Why you might be asking. Well I was asking to my self too. Here is where it gets used;
if (ws.is_channel_delete) {
const deletedChannel = {
...ws.new_channel,
is_deleted: true
};
broadcastConnectedUsers(ws, user_ids, 'channel_delete', deletedChannel);
}
Now it makes sense right? Right?? RIGHT??? No it doesn't really. I mean it works correctly since the logic is not wrong. But the way the logic is executed. Oh god, it makes me question my life choices. It could've been kept in the same method. I mean they don't even use the method that calls the second block else where. It's only called for delete channel action...